package com.cta.view.model.discount;

import org.joda.time.DateTime;

import com.cta.entity.DiscountRate;
import com.cta.view.model.CallData;

public class DayOfWeekDiscountModel extends DiscountModel {

	public DayOfWeekDiscountModel(DiscountRate orgDiscount) {
		super(orgDiscount);
	}
	
	public DayOfWeekDiscountModel(DiscountRate orgDiscount, int discountVal) {
		super(orgDiscount, discountVal);
	}

	@Override
	public void hasDiscount(CallData data) throws Exception {
		DateTime callDate = data.getDate();
		if (callDate.dayOfWeek().getAsShortText().equals(this.orgDiscount.getCondition())) {
			log.info(String.format("Has dayofweek discount-> callday: %s, offDay: %s", callDate.dayOfWeek()
					.getAsShortText(), this.orgDiscount.getCondition()));
			data.getDayDiscounts().put(callDate.toLocalDate().withYear(0).toString(), this);
		}
	}

}
